﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.IO;

namespace SPThumbnailExtender.Interne
{
    internal static class ThumbnailFactory
    {
        public static ThumbnailBase GenerateThumbnail(Uri uriFile)
        {
            string strPath = uriFile.AbsoluteUri;
            string strExt= Path.GetExtension(strPath);
            if(strExt.IndexOf('?') >0)
                strExt=strExt.Substring(0, strExt.IndexOf('?'));
            switch(strExt){
                case ".pdf":
                    return new ThumbnailPDF(uriFile);
                case ".wmv":
                    return new ThumbnailWMV(uriFile);
                case ".doc":
                case ".docx":
                    return new ThumbnailWord(uriFile);
                case ".pptx":
                case ".ppt":
                    return new ThumbnailPowerPoint(uriFile);
                case ".dwg":
                    return new ThumbnailDWG(uriFile);
                case ".html":
                case ".htm":
                case ".aspx":
                case ".php":
                    return new ThumbnailHtml(uriFile);
                case ".bmp":
                case ".tiff":
                case ".tif":
                case ".gif":
                case ".png":
                case ".jpg":
                case ".jpeg":
                case ".wmf":
                    return new ThumbnailImage(uriFile);
                case ".xlsx":
                    return new ThumbnailOpenXML(uriFile);
                case ".xps":
                    return new ThumbnailXPS(uriFile);
                case ".zip":
                    return new ThumbnailZip(uriFile);
                default:
                    if(uriFile.AbsoluteUri.EndsWith("/"))
                        return new ThumbnailHtml(uriFile);
                    break;
            }
            return null;
        }
    }
}
